function get(url,callback){
    var ajax = new XMLHttpRequest();
    ajax.onreadystatechange = ()=>{
        if(ajax.readyState==4 && ajax.status==200){
            var json = ajax.responseText;
            var result = JSON.parse(json);
            callback(result);
        }
    }
    ajax.open("get",url);
    ajax.send(null);
}


function post(url,data,callback){
    var ajax = new XMLHttpRequest();
    ajax.onreadystatechange = ()=>{
        if(ajax.readyState==4 && ajax.status==200){
            var json = ajax.responseText;
            var result = JSON.parse(json);
            callback(result);
        }
    }
    ajax.open("post",url);
    //设置提交数据的内容数据
    if(data instanceof String){
        // 表单提交的数据
        ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    }else if(data instanceof FormData){
        //文件上传
        ajax.setRequestHeader("Content-Type","multipart/form-data")
    }
    ajax.send(data);
}